<?php defined('SYSPATH') or die('No direct script access.');

class Controller_Welcome extends Controller {

	public function action_index()
	{
		$this->response->body('hello, world!');
	}

	public function action_db()
	{
		$tables = array('sp_yxgw', 'sp_sys_user', 'sp_sys_userpermission', 'sp_permission', 'sp_role_permission', 'sale_customer', 'sale_customer_stat','bargain_package_list','sale_package','sp_user');//'sale_customer', 'sale_visitlog', 'bargain_package_list', 
		foreach($tables as $tablename)
		{
			$result = DB::query(Database::SELECT, 'show create table ' . $tablename)->execute('leju3310')->as_array();
			$tableinfo = $result[0]['Create Table'];
			$tableinfo = mb_convert_encoding($tableinfo, 'UTF-8', 'GBK,ASCII,JIS,UTF-8,EUC-JP,SJIS');
			$tableinfo = nl2br($tableinfo);
			echo $tableinfo . '<hr>';
		}
	}
	public function action_sql() {
		$sql = "ALTER TABLE `sale_customer` ADD COLUMN `buy_status` TINYINT NOT NULL COMMENT '签约状态，1已签约，0未签约'  AFTER `udate` , ADD COLUMN `bargain_start_date` DATE NOT NULL  AFTER `buy_status` , ADD COLUMN `bargain_end_date` DATE NOT NULL  AFTER `bargain_start_date` , ADD COLUMN `bargain_type` TINYINT NOT NULL COMMENT '1端口 2认证\','  AFTER `bargain_end_date` , ADD COLUMN `bargain_id` INT NOT NULL COMMENT '合同表id，关联表sale_package'  AFTER `bargain_type` , ADD COLUMN `sys_user_id` INT NOT NULL COMMENT '业务代表'  AFTER `bargain_id` , ADD COLUMN `sys_user_name` VARCHAR(255) NOT NULL COMMENT '业务代表名'  AFTER `sys_user_id` ";
		$sql = iconv('UTF-8', 'GBK', $sql);
		DB::query(Database::CREATE, $sql)->execute('leju3310');
	}
	public function action_showdata() {
		$sql = "select * from sale_package";
		$rs = DB::query(Database::SELECT, $sql)->execute('leju3310')->as_array();
		$view = View::factory('showdata');
		$view->data = $rs;
		$this->response->body($view);
	}
	public function action_test() {
		$aO = new A();
		echo $aO->a;
	}
}

class A {
	private $a = 1;

	public function __get($name) {
		return $this->$name;
	}
}
